/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.furb.trabalhoFinal.view;

import br.com.furb.trabalhoFinal.Strategy.AreaTextoStrategy;
import br.com.furb.trabalhoFinal.Strategy.ArquivoTextoStrategy;
import br.com.furb.trabalhoFinal.Strategy.ClipBoardStrategy;
import br.com.furb.trabalhoFinal.Strategy.SaidaStrategy;
import br.com.furb.trabalhoFinal.Utils.Aplicacao;
import br.com.furb.trabalhoFinal.controller.GeradorDeFolha;
import br.com.furb.trabalhoFinal.model.Colaborador;
import br.com.furb.trabalhoFinal.model.Marcacoes;
import br.com.furb.trabalhoFinal.model.Folha;
import java.security.acl.Group;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author Jonathan
 */
public class FolhaTela extends javax.swing.JFrame {

    /**
     * Creates new form FolhaTela
     */
    public FolhaTela() {
        initComponents();
        grpBox.add(jRBAreaTexto);
        grpBox.add(jRBClipBoard);
        grpBox.add(jRBArquivoTexto);
        Colaborador col = Aplicacao.getInstance().getUsuarioLogado();
        if(col != null){
        for(Date data: col.getMarcacoes().keySet()){
          GregorianCalendar cal = new GregorianCalendar();
          cal.setTime(data);
          Object xRef = "" + cal.MONTH + "/" + cal.YEAR;
          jCBReferencia.addItem(xRef);
        }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grpBox = new javax.swing.ButtonGroup();
        jRBAreaTexto = new javax.swing.JRadioButton();
        jRBClipBoard = new javax.swing.JRadioButton();
        jRBArquivoTexto = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jCBReferencia = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        btnGerarFolha = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jRBAreaTexto.setText("Área de Texto");

        jRBClipBoard.setText("ClipBoard");

        jRBArquivoTexto.setText("Arquivo Texto");

        jLabel1.setText("Saída");

        jLabel2.setText("Referência");

        btnGerarFolha.setText("Gerar Folha");
        btnGerarFolha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGerarFolhaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRBAreaTexto)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jRBClipBoard)
                        .addGap(18, 18, 18)
                        .addComponent(jRBArquivoTexto))
                    .addComponent(jLabel1))
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCBReferencia, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE))
                .addGap(37, 37, 37)
                .addComponent(btnGerarFolha, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRBAreaTexto)
                    .addComponent(jRBClipBoard)
                    .addComponent(jRBArquivoTexto)
                    .addComponent(jCBReferencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGerarFolha))
                .addContainerGap(535, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

  private void btnGerarFolhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGerarFolhaActionPerformed
    SaidaStrategy strategy = getStrategy();
    GeradorDeFolha gerador = new GeradorDeFolha();
    String item = (String) jCBReferencia.getSelectedItem();
    String[] strings = item.split("/");
    Date date = new Date(Integer.parseInt(strings[1]), Integer.parseInt(strings[0]), 0);
    Folha folha = gerador.gerarFolha(Aplicacao.getInstance().getUsuarioLogado(), date);
    strategy.gerarFolha(folha.toString());
  }//GEN-LAST:event_btnGerarFolhaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FolhaTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FolhaTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FolhaTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FolhaTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FolhaTela().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGerarFolha;
    private javax.swing.ButtonGroup grpBox;
    private javax.swing.JComboBox jCBReferencia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRBAreaTexto;
    private javax.swing.JRadioButton jRBArquivoTexto;
    private javax.swing.JRadioButton jRBClipBoard;
    // End of variables declaration//GEN-END:variables

  private SaidaStrategy getStrategy() {
    if(jRBAreaTexto.isSelected()){
      return new AreaTextoStrategy();
    }
    if(jRBClipBoard.isSelected()) {
      return new ClipBoardStrategy();
    }
    return new ArquivoTextoStrategy();
  }
}
